#include "clocker.h"
#include <stdio.h>
#include <string.h>
// #include <linux/time.h>

#define log(...) do {                \
            printf(__VA_ARGS__);     \
            printf("\n");            \
        } while(0);

struct clocker_object
{
    int num;
    struct timespec start;
    struct timespec end;
	double duration;
};

struct clocker_object clk;

static int device_carry_out_numbering = 0;

int clocker_start(void)
{
    memset(&clk, 0, sizeof(struct clocker_object));
    clk.num = device_carry_out_numbering++;

    clock_gettime(CLOCK_MONOTONIC, &clk.start);
    log("----------------- clocker : num:[%d] start -----------------", clk.num);
}

int clocker_end(void)
{
    clock_gettime(CLOCK_MONOTONIC, &clk.end);
	clk.duration = (double)(clk.end.tv_nsec - clk.start.tv_nsec)/((double) 1e9) + (double)(clk.end.tv_sec-clk.start.tv_sec);
	log("----------------- clocker : num:[%d] end   -----------------", clk.num);
    log("> clocker : num [%d] run time [%f] s ...", clk.num, clk.duration);
}
